//
//  BestView.m
//  InitView
//
//  Created by 曾墨 on 16/8/30.
//  Copyright © 2016年 YuanJiang. All rights reserved.
//

#import "BestView.h"

@interface BestView()
@property(nonatomic,strong) UIButton *currentBtn;

@end

@implementation BestView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
       //btn1
        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn1.frame =CGRectMake(100, 50, 70, 40);
        [btn1 setTitle:@"选中" forState:UIControlStateNormal];
        [btn1 addTarget:self action:@selector(QWQ:) forControlEvents:UIControlEventTouchUpInside];
        [btn1 setBackgroundColor:[UIColor greenColor]];
        [self addSubview:btn1];
        
        
        //btn2
        UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn2.frame =CGRectMake(100, 150, 70, 40);
        [btn2 setTitle:@"未选中" forState:UIControlStateNormal];
        [btn2 addTarget:self action:@selector(QWQ:) forControlEvents:UIControlEventTouchUpInside];
        [btn2 setBackgroundColor:[UIColor redColor]];
        [self addSubview:btn2];
        
        self.currentBtn = btn1;
        self.currentBtn.selected =YES;
        if (self.currentBtn.selected ==YES) {
            [self.currentBtn setTitle:@"选中" forState:UIControlStateNormal];
            [self.currentBtn setBackgroundColor:[UIColor greenColor]];
        }else{
            [self.currentBtn setTitle:@"未选中" forState:UIControlStateNormal];
            [self.currentBtn setBackgroundColor:[UIColor redColor]];
        }
        
        
    }
    return self;
}

-(void)QWQ:(UIButton *)sender
{
    self.currentBtn.selected =NO;
    [self.currentBtn setTitle:@"未选中" forState:UIControlStateNormal];
    [self.currentBtn setBackgroundColor:[UIColor redColor]];
    
    self.currentBtn = sender;
    [self.currentBtn setTitle:@"选中" forState:UIControlStateNormal];
    [self.currentBtn setBackgroundColor:[UIColor greenColor]];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
